<!DOCTYPE html>
<html>
<head>
    <title>门诊查询--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            var alls = document.getElementsByName("check");
            var ch = document.getElementById("checkall");
            ch.checked = true;
            for (var i = 0; i < alls.length; i++) {
                if (alls[i].checked == false) {
                    ch.checked = false;
                    i = alls.length;
                }
            }
            $('#newNav').click(function () {
                window.location.href = "add.html";
            });
            loadData();
            $("#firstPage").click(function () {
                let num = $(this).attr("name");
                $("#pageNum").html(num);
                $("#realPageNum").val(num);
                loadData();
            });
            $("#prePage").click(function () {
                let num = $(this).attr("name");
                $("#pageNum").html(num);
                $("#realPageNum").val(num);
                loadData();
            });
            $("#nextPage").click(function () {
                let num = $("#nextPage").attr("name");
                $("#pageNum").html(num);
                $("#realPageNum").val(num);
                loadData();
            });
            $("#lastPage").click(function () {
                let num = $(this).attr("name");
                $("#pageNum").html(num);
                $("#realPageNum").val(num);
                loadData();
            });
            $("#1").click(function () {
                let num = $(this).attr("name");
                $("#pageNum").html(num);
                $("#realPageNum").val(num);
                loadData();
            });
            $("#2").click(function () {
                let num = $(this).attr("name");
                $("#pageNum").html(num);
                $("#realPageNum").val(num);
                loadData();
            });
            $("#3").click(function () {
                let num = $(this).attr("name");
                $("#pageNum").html(num);
                $("#realPageNum").val(num);
                loadData();
            });
            $("#4").click(function () {
                let num = $(this).attr("name");
                $("#pageNum").html(num);
                $("#realPageNum").val(num);
                loadData();
            });
            $("#5").click(function () {
                let num = $(this).attr("name");
                $("#pageNum").html(num);
                $("#realPageNum").val(num);
                loadData();
            });
        });

        function checkall() {
            var alls = document.getElementsByName("check");
            var ch = document.getElementById("checkall");
            if (ch.checked) {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = true;
                }
            } else {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = false;
                }
            }
        }

        function delAll() {
            var alls = document.getElementsByName("check");
            var ids = new Array();
            for (var i = 0; i < alls.length; i++) {
                if (alls[i].checked) {
                    ids.push(alls[i].value);
                }
            }
            if (ids.length > 0) {
                if (confirm("确认操作?")) {
                    $.ajax({
                        type: "POST",
                        url: "/registration/deleteAll/" + ids, //RESTful风格的API定义
                        data: "_method=DELETE",
                        success: function (vo) {
                            if (vo.code == 200) {
                                alert("成功!");
                                let pageNum = $("input[name='pageNum']").val();
                                loadData(pageNum);
                            } else {
                                alert("退号失败！" + vo.msg);
                            }
                        }
                    });
                }
            } else {
                alert("请选中要操作的项");
            }
        }


        function fillPageData(pageInfo) {
            //填充信息
            $("#total").html(pageInfo.total);
            $("#pages").html(pageInfo.pages);
            $("#pageNum").html(pageInfo.pageNum);
            $("#realPageNum").val(pageInfo.pageNum);
            if (pageInfo.isFirstPage) {
                $("#1").html(pageInfo.pageNum);
                $("#2").html(pageInfo.pageNum + 1);
                $("#3").html(pageInfo.pageNum + 2);
                $("#4").html(pageInfo.pageNum + 3);
                $("#5").html(pageInfo.pageNum + 4);
                $("#1").attr("name", pageInfo.pageNum);
                $("#2").attr("name", pageInfo.pageNum + 1);
                $("#3").attr("name", pageInfo.pageNum + 2);
                $("#4").attr("name", pageInfo.pageNum + 3);
                $("#5").attr("name", pageInfo.pageNum + 4);
            } else if (pageInfo.pageNum == 2) {
                $("#1").html(pageInfo.pageNum - 1);
                $("#2").html(pageInfo.pageNum);
                $("#3").html(pageInfo.pageNum + 1);
                $("#4").html(pageInfo.pageNum + 2);
                $("#5").html(pageInfo.pageNum + 3);
                $("#1").attr("name", pageInfo.pageNum - 1);
                $("#2").attr("name", pageInfo.pageNum);
                $("#3").attr("name", pageInfo.pageNum + 1);
                $("#4").attr("name", pageInfo.pageNum + 2);
                $("#5").attr("name", pageInfo.pageNum + 3);
            } else {
                $("#1").html(pageInfo.pageNum - 2);
                $("#2").html(pageInfo.pageNum - 1);
                $("#3").html(pageInfo.pageNum);
                $("#4").html(pageInfo.pageNum + 1);
                $("#5").html(pageInfo.pageNum + 2);
                $("#1").attr("name", pageInfo.pageNum - 2);
                $("#2").attr("name", pageInfo.pageNum - 1);
                $("#3").attr("name", pageInfo.pageNum);
                $("#4").attr("name", pageInfo.pageNum + 1);
                $("#5").attr("name", pageInfo.pageNum + 2);
            }

            $("#1").css("color", "");
            $("#2").css("color", "");
            $("#3").css("color", "");
            $("#4").css("color", "");
            $("#5").css("color", "");
            $("#1").css("opacity", "");
            $("#2").css("opacity", "");
            $("#3").css("opacity", "");
            $("#4").css("opacity", "");
            $("#5").css("opacity", "");
            if (pageInfo.pageNum == $("#1").html()) {
                $("#1").css("color", "red");
            }
            if (pageInfo.pages < $("#1").html()) {
                $("#1").css("opacity", 0.2);
                $("#1").attr("name", pageInfo.pageNum);
            }
            if (pageInfo.pageNum == $("#2").html()) {
                $("#2").css("color", "red");
            }
            if (pageInfo.pages < $("#2").html()) {
                $("#2").css("opacity", 0.2);
                $("#2").attr("name", pageInfo.pageNum);
            }
            if (pageInfo.pageNum == $("#3").html()) {
                $("#3").css("color", "red");
            }
            if (pageInfo.pages < $("#3").html()) {
                $("#3").css("opacity", 0.2);
                $("#3").attr("name", pageInfo.pageNum);
            }
            if (pageInfo.pageNum == $("#4").html()) {
                $("#4").css("color", "red");
            }
            if (pageInfo.pages < $("#4").html()) {
                $("#4").css("opacity", 0.2);
                $("#4").attr("name", pageInfo.pageNum);
            }
            if (pageInfo.pageNum == $("#5").html()) {
                $("#5").css("color", "red");
            }
            if (pageInfo.pages < $("#5").html()) {
                $("#5").css("opacity", 0.2);
                $("#5").attr("name", pageInfo.pageNum);
            }
            //设置按钮的属性值和样式
            $("#firstPage").attr("name", 1);
            $("#prePage").attr("name", pageInfo.prePage);
            $("#nextPage").attr("name", pageInfo.nextPage);
            $("#lastPage").attr("name", pageInfo.pages);
            $("#firstPage").css("opacity", "");
            $("#prePage").css("opacity", "");
            $("#nextPage").css("opacity", "");
            $("#lastPage").css("opacity", "");
            $("#firstPage").attr("onclick", "");
            $("#prePage").attr("onclick", "");
            $("#nextPage").attr("onclick", "");
            $("#lastPage").attr("onclick", "");
            if (pageInfo.isFirstPage) {//如果是第一页：上一页和首页禁用
                $("#firstPage").css("opacity", 0.2);
                $("#prePage").css("opacity", 0.2);
                $("#prePage").attr("name", pageInfo.pageNum);
            }
            if (pageInfo.isLastPage) {//如果已经是最后一页：下一页和末页禁用
                $("#nextPage").css("opacity", 0.2);
                $("#lastPage").css("opacity", 0.2);
                $("#nextPage").attr("name", pageInfo.pageNum);

            }
        }

        function checkAllInfo(id) {
            let pageNum = $("#realPageNum").val();
            let pageSize = 5;
            window.location.href = "look.html?id=" + id + "&pageNum=" + pageNum + "&pageSize=" + pageSize;
        }

        function updateAllInfo(id) {
            let pageNum = $("#realPageNum").val();
            let pageSize = 5;
            window.location.href = "edit.html?id=" + id + "&pageNum=" + pageNum + "&pageSize=" + pageSize;
        }

        function deleteRegister(id) {
            if (confirm("确定要退号吗?")) {
                //发起异步请求
                $.ajax({
                    type: "POST",
                    url: "/registration/delete/" + id, //RESTful风格的API定义
                    data: "_method=DELETE",
                    success: function (vo) {
                        if (vo.code == 200) {
                            let pageNum = $("input[name='pageNum']").val();
                            loadData(pageNum);
                        } else {
                            alert("退号失败！" + vo.msg);
                        }
                    }
                });
            }
        }

        String.prototype.GetValue = function (para) {
            let reg = new RegExp("(^|&)" + para + "=([^&]*)(&|$)");
            let r = this.substr(this.indexOf("\?") + 1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        function loadData() {
            let url = document.location.toString();
            let pageNum = url.GetValue("pageNum");
            if (pageNum != null && $("#pageNum").html() != null) {
                $("#pageNum").html(pageNum);
                $("#realPageNum").val(pageNum);
            }
            $.ajax({
                type: "GET",
                url: "/registration/list/",
                data: $("#myForm").serialize(),

                //主要是分页和多条件参数数据
                dataType: "json",
                success: function (vo) {
                    //alert( "Data Saved: " + vo );
                    let list = vo.pageInfo.list;
                    let str = "";
                    for (let i = 0; i < list.length; i++) {
                        let obj = list[i];
                        let id = obj.id;
                        let doctorName = obj.doctor.name;
                        let date = obj.date == null ? '' : obj.date;
                        let keShi = obj.doctor.keShi;
                        let state = "";
                        if (obj.state == 0)
                            state = '挂号';
                        if (obj.state == 1)
                            state = '已住院';
                        if (obj.state == 2)
                            state = '已出院';
                        if (obj.state == 3)
                            state = '已退号';
                        str += '<tr>' +
                            '            <td style="vertical-align:middle;"><input type="checkbox" name="check" value="' + id + '"></td>' +
                            '            <td style="vertical-align:middle;">' + id + '</td>' +
                            '            <td style="vertical-align:middle;">' + doctorName + '</td>' +
                            '            <td style="vertical-align:middle;">' + date + '</td>' +
                            '            <td style="vertical-align:middle;">' + keShi + '</td>' +
                            '            <td style="vertical-align:middle;">' + state + '</td>';
                        if (state == "挂号") {
                            str += '<td style="vertical-align:middle;"><a href="#" onclick="checkAllInfo(' + id + ')">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="#" onclick="updateAllInfo(' + id + ')">更改</a>&nbsp;&nbsp;&nbsp;<a href="#" onclick="deleteRegister(' + id + ')">退号</a></td>' +
                                '</tr>';
                        }
                        if (state == "已住院") {
                            str += '<td style="vertical-align:middle;"><a href="#" onclick="checkAllInfo(' + id + ')">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="#" onclick="updateAllInfo(' + id + ')">更改</a>' +
                                '</tr>';
                        }
                        if (state == "已出院") {
                            str += '<td style="vertical-align:middle;"><a href="#" onclick="checkAllInfo(' + id + ')">详情>>></td>' +
                                '</tr>';
                        }
                        if (state == "已退号") {
                            str += '<td style="vertical-align:middle;"><a href="#" onclick="checkAllInfo(' + id + ')">详情>>></td>' +
                                '</tr>';
                        }

                    }
                    $("#tboby").html(str);
                    //填充分页数据
                    fillPageData(vo.pageInfo);
                }
            });
        }

        function empty() {
            $("input[name='id']").val("")
            $("input[name='doctorName']").val("")
            $("input[name='keShi']").val("")
            $("input[name='beginDate']").val("")
            $("input[name='endDate']").val("")
        }

    </script>

</head>
<body>

<form id="myForm" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">病历号：</td>
            <td><input type="text" name="id" value=""/></td>

            <td width="10%" class="tableleft">主治医生：</td>
            <td><input type="text" name="doctorName" value=""/></td>

            <td width="10%" class="tableleft">科室：</td>
            <td><input type="text" name="keShi" value=""/></td>
        </tr>
        <tr>

            <td width="10%" class="tableleft">挂号时间：</td>

            <td colspan="5">
                <input type="text" name="beginDate" value=""/>&nbsp;至&nbsp;<input type="text" name="endDate" value=""/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button class="btn btn-primary" type="button" onclick="loadData()">查询</button>
                <button class="btn btn-primary" type="button" onclick="empty()">清空</button>

            </td>
        </tr>
        <input id="realPageNum" name="realPageNum" value="" type="hidden">
    </table>

</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th><input type="checkbox" id="checkall" onChange="checkall();"></th>
        <th>门诊编号</th>
        <th>主治医生</th>
        <th>挂号时间</th>
        <th>挂号科室</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tboby">
    <tr>
        <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
        <td style="vertical-align:middle;">1103</td>
        <td style="vertical-align:middle;">程俊</td>
        <td style="vertical-align:middle;">2015-09-09 12：12：12</td>
        <td style="vertical-align:middle;">血液科</td>
        <td style="vertical-align:middle;">已挂号</td>
        <td style="vertical-align:middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="edit.html">更改</a>&nbsp;&nbsp;&nbsp;<a
                href="javascript:alert('退号成功！');">退号</a></td>
    </tr>
    <tr>
        <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
        <td style="vertical-align:middle;">1104</td>
        <td style="vertical-align:middle;">王博</td>
        <td style="vertical-align:middle;">2015-12-09 12：12：12</td>
        <td style="vertical-align:middle;">骨科</td>
        <td style="vertical-align:middle;">已住院</td>
        <td style="vertical-align:middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="edit.html">更改</a>
        </td>
    </tr>
    <tr>
        <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
        <td style="vertical-align:middle;">1105</td>
        <td style="vertical-align:middle;">沈青川</td>
        <td style="vertical-align:middle;">2015-02-04 15：11：12</td>
        <td style="vertical-align:middle;">外科</td>
        <td style="vertical-align:middle;">已住院</td>
        <td style="vertical-align:middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="edit.html">更改</a>
        </td>
    </tr>
    <tr>
        <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
        <td style="vertical-align:middle;">1106</td>
        <td style="vertical-align:middle;">欧阳雨露</td>
        <td style="vertical-align:middle;">2014-09-05 12：12：12</td>
        <td style="vertical-align:middle;">急诊科</td>
        <td style="vertical-align:middle;">已出院</td>
        <td style="vertical-align:middle;"><a href="look.html">详情>>></td>
    </tr>
    <tr>
        <td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
        <td style="vertical-align:middle;">1107</td>
        <td style="vertical-align:middle;">艾小天</td>
        <td style="vertical-align:middle;">2014-02-09 12：12：11</td>
        <td style="vertical-align:middle;">妇科</td>
        <td style="vertical-align:middle;">已退号</td>
        <td style="vertical-align:middle;"><a href="look.html">详情>>></td>
    </tr>
    </tbody>

</table>

<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <th colspan="5">
            <div class="inline pull-right page">
                <a id="firstPage" name="pageLi" href='#'>第一页</a> <a id="prePage" name="pageLi" href='#'>上一页</a>
                <a id="1" href="#">1</a>
                <a id="2" href="#">2</a>
                <a id="3" href="#">3</a>
                <a id="4" href='#'>4</a>
                <a id="5" href='#'>5</a>
                <a id="nextPage" name="pageLi" href='#'>下一页</a>
                <a id="lastPage" name="pageLi" disabled="true" href='#'>最后一页</a>
                &nbsp;&nbsp;&nbsp;共<span class='current'><span id="total"></span></span>条记录<span class='current'><span
                    id="pageNum"></span>/<span id="pages"></span></span>页
            </div>
            <div>
                <button type="button" class="btn btn-success" id="newNav">门诊挂号</button>&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-success" id="delPro" onClick="delAll();">退号</button>&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-success">导出Excel</button>


            </div>

        </th>
    </tr>
</table>

</body>
</html>


